// import { lazy } from 'react';
// import { Router, Route, Link } from 'react-router';

const path = require('path');
const fs = require('fs');

// 页面目录
const pagesDirPath = path.resolve(__dirname, '../pages');

function getJSXFilePathByDir(dirPath) {
  const jsxFilePathList = [];

  if(!fs.statSync(dirPath).isDirectory()) {
    return jsxFilePathList;
  }

  fs.readdirSync(dirPath).forEach(file => {
    const filePath = path.join(dirPath, file);

    if(fs.statSync(filePath).isDirectory()) {
      const jsxFileListTmp = getJSXFilePathByDir(filePath);

      if(jsxFileListTmp.length > 0) {
        jsxFilePathList.push(...jsxFileListTmp);
      }
    }
    if(path.extname(filePath) === '.jsx') {
      jsxFilePathList.push(filePath);
    }
  });

  return jsxFilePathList;
}

function getAllPageAbsolutePath() {
  const pagePathList = [];

  fs.readdirSync(pagesDirPath).forEach(page => {
    if(fs.statSync(pagesDirPath).isDirectory()) {
      const jsxFilePathList = getJSXFilePathByDir(path.join(pagesDirPath, page));

      if(jsxFilePathList.length > 0) {
        pagePathList.push(...jsxFilePathList);
      }
    }
  });

  return pagePathList;
}

function getRouterDom() {
  return (
    <Router>
      { getAllPageAbsolutePath().map(pageAbsolutePath => {
          return <Route></Route>
      })}
    </Router>
  );
}

getRouterDom();